package com.ym.controller.soso;

import com.github.pagehelper.PageInfo;
import com.ym.base.enums.FlagEnum;
import com.ym.common.utils.page.PageDomain;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.medical.domain.entity.MedicalCentreEntity;
import com.ym.medical.domain.param.MedicalCentreQueryParam;
import com.ym.medical.domain.param.MedicalCentreUpdateParam;
import com.ym.medical.domain.vo.MedicalCentreListPcVO;
import com.ym.medical.service.IMedicalCentreSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

import static com.ym.common.constant.ValidRule.Add;
import static com.ym.common.constant.ValidRule.Update;

/**
 * 体检中心Controller
 * 
 * @author ym
 * @date 2020-09-02
 */
@Api(tags = "medical-体检中心")
@RestController("MedicalCentrePcController")
@Validated
@RequestMapping("/medical/centre")
public class MedicalCentreController extends BaseController {

    @Autowired
    private IMedicalCentreSV medicalCentreSV;

    @ApiOperation("查询体检中心列表")
    @Log(dataBase = false, printBody = false, printQuery = true)
    @GetMapping("/list")
    public APIResponse<PageInfo<MedicalCentreListPcVO>> list(@Valid MedicalCentreQueryParam queryParam) {
        PageDomain.startPage();
        queryParam.setDeleted(FlagEnum.NO.getKey());
        List<MedicalCentreListPcVO> list = medicalCentreSV.selectListPC(queryParam);
        return successPage(list);
    }

    @ApiOperation("获取体检中心详细信息")
    @Log(dataBase = false, printBody = false, printQuery = true)
    @GetMapping(value = "/info")
    public APIResponse<MedicalCentreEntity> info(@RequestParam Long id) {
        MedicalCentreEntity data = medicalCentreSV.selectById(id);
        return successData(data);
    }

    @ApiOperation("新增体检中心")
    @Log(printQuery = false)
    @PostMapping("/insert")
    public APIResponse insert(@RequestBody @Validated(value = Add.class) MedicalCentreUpdateParam updateParam) {
        Long id = medicalCentreSV.insertPC(updateParam);
        return successData(id);
    }

    @ApiOperation("修改体检中心")
    @Log(printQuery = false)
    @PostMapping("/update")
    public APIResponse update(@RequestBody @Validated(value = Update.class) MedicalCentreUpdateParam updateParam) {
        int result = medicalCentreSV.updateByIdPC(updateParam);
        return successData(result);
    }

    @ApiOperation("删除体检中心")
    @Log(printQuery = false)
    @PostMapping("/delete")
    public APIResponse delete(@RequestBody @Valid @NotNull Long[] ids) {
        MedicalCentreEntity medicalCentreEntity = new MedicalCentreEntity();
        medicalCentreEntity.setDeleted(FlagEnum.IS.getKey());
        medicalCentreSV.updateByIds(medicalCentreEntity,ids);
        return success();
    }
}
